package com.bieyang.anjia.ui.adapter;

import java.util.List;

import com.bieyang.anjia.R;
import com.bieyang.anjia.module.FileModel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AlarmAdapter extends BaseAdapter {
	List<FileModel> list;
	LayoutInflater inflater;
	Context con;

	public AlarmAdapter(List<FileModel> list, Context context) {
		inflater = LayoutInflater.from(context);
		con = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.alarm_happen_item, null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		FileModel model = list.get(position);
		holder.alarmTime.setText(model.time);
		holder.alarmType.setText(model.alarmType);
		if ("null".equals(model.name)) {
			if (model.uuid.length() > 10) {
				model.name = model.uuid.substring(model.uuid.length() - 10);
			} else {
				model.name = "";
			}
		}
		holder.alarmName.setText(model.name
				+ con.getString(R.string.detailed_alarm_info));
		if (model.isnew.equals("F")) {
			holder.alarmName.setTextColor(con.getResources().getColor(
					R.color.front_black));
		} else {
			holder.alarmName.setTextColor(con.getResources().getColor(
					R.color.grey));
		}
		return convertView;
	}

	public class ViewHolder {
		ImageView alarmIcon;
		TextView alarmName, alarmType, alarmTime;

		public ViewHolder(View view) {
			alarmName = (TextView) view.findViewById(R.id.alarmItemName);
			alarmType = (TextView) view.findViewById(R.id.alarmItemType);
			alarmTime = (TextView) view.findViewById(R.id.alarmItemTime);
			alarmIcon = (ImageView) view.findViewById(R.id.alarmItemImg);
		}
	}
}
